<template>
  <div id="music">
    <van-loading size="24px"
                 vertical
                 type="spinner"
                 v-if="loading_01">拼命加载中...</van-loading>
    <van-list v-model="loading"
              :finished="finished"
              finished-text="我是有底线的～"
              @load="onLoad"
              :immediate-check="false">
      <!-- <van-pull-refresh v-model="refreshing"
                        @refresh="onRefresh"> -->
      <a href="##">
        <div class="box"
             v-for="(item, i) in musicList"
             :key="i + 't'">
          <div class="musleft">
            <p><a href=""><img :src="item.thumPic"></a></p>
            <p><img src="@/assets/two/musmus_03.jpg"></p>
          </div>
          <div class="musright">
            <p><img src="@/assets/two/mu02.jpg"
                   alt="">{{ item.title }}</p>
            <div class="boxx">
              <div class="leanl">
                <p>{{ fornum(item.duration) }}s</p>
                <p>时长</p>
              </div>
              <div class="leanr">
                <p>{{ format_num(item.userCount) }}</p>
                <p>使用人数</p>
              </div>
            </div>
          </div>
        </div>
      </a>
      <span class="bot"></span>
      <!-- </van-pull-refresh> -->
    </van-list>
    <div v-if="musicList.length == 0 && show">
      <img class="img"
           src="../../../assets/three/Collection.png"
           alt="" />
      <p class="Collection">您尚未收藏任何音乐</p>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import { Toast } from 'vant'
Vue.use(Toast)
export default {
  name: '',
  components: {},
  data() {
    return {
      page: 1,
      pageSize: 20,
      musicList: [],
      //触底
      loading: false,
      finished: false,
      refreshing: false,
      show: false,
      loading_01: false,
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.GetmusicList()
  },

  methods: {
    GetmusicList() {
      // this.loading = true
      this.loading_01 = true
      this.$axios
        .get('/api/collection/GetMusicCollection', {
          params: {
            pageIndex: this.page,
            pageSize: this.pageSize,
          },
        })
        .then((res) => {
          if (res.data.code == 0) {
            this.musicList = this.musicList.concat(res.data.data)
            this.loading = false
            this.refreshing = false
            this.show = true
            this.loading_01 = false
            if (
              res.data.data.length < this.pageSize &&
              res.data.data.length != 0
            ) {
              this.finished = true
            }
          } else if (res.data.code == 1002) {
            this.loading = false
            this.show = true
            this.loading_01 = false
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },

    //触底
    onLoad() {
      this.loading = true
      if (this.page * this.pageSize > this.musicList.length) {
        if (this.musicList.length == 0) {
          this.loading = false
          this.finished = false
        } else {
          this.loading = false
          this.finished = true
        }
      } else if (this.musicList.length > 0) {
        this.page = this.page + 1;
        this.GetmusicList()
      }
    },
    onRefresh() {
      // 清空列表数据
      //   this.finished = false;
      this.pageIndex = 1
      this.musicList = []
      this.GetmusicList()
    },
  },
}
</script>


<style scoped lang="less">
#music {
  background: #f1f1f1;
  min-height: 100vh;
  a {
    text-decoration: none;
  }
/*   img {
    display: inline-block;
  } */
  .box {
    width: 92%;
    margin: 0 auto;
    border: 1px solid transparent;
    border-radius: 8px;
    background: #fff;
    display: flex;
    margin-top: 0.186667rem;
    .musleft {
      width: 30%;
      padding: 7.2% 0 0 8%;
      position: relative;
      p:nth-of-type(1) {
        width: 2.133333rem;
        height: 2.133333rem;
        position: absolute;
        left: 0.266667rem;
        top: 0.266667rem;
        z-index: 10;
        a {
          display: block;
          width: 100%;
          height: 100%;
        }
      }
      p:nth-of-type(2) {
        width: 1.6rem;
        height: 1.6rem;
        position: absolute;
        right: 10.8%;
        top: 22%;
      }
      img {
        display: block;
        width: 100%;
        border: 1px solid transparent;
        border-radius: 0.213rem;
      }
    }
    // 右侧
    .boxx {
      display: flex;
    }
    .musright {
      width: 68.9%;
      padding-top: 0.613333rem;
      > p {
        font-size: 0.373333rem;
        line-height: 0.373333rem;
        color: #fd7f2c;
        padding-bottom: 0.426667rem;
        // 溢出显示三个点
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .musright > p > img {
      width: 0.4rem;
      margin-right: 10px;
    }
    .leanl {
      width: 3.013333rem;
      p {
        font-size: 0.266667rem;
        line-height: 0.266667rem;
      }
    }
    .musright .leanr p {
      font-size: 0.266667rem;
      line-height: 0.266667rem;
    }
    .musright .leanl p:nth-of-type(1),
    .musright .leanr p:nth-of-type(1) {
      padding-bottom: 0.133333rem;
      font-size: 0.266667rem;
      color: #222;
      font-family: Dinpro-medium;
      font-weight: 600;
    }
    .musright .leanl p:nth-of-type(2),
    .musright .leanr p:nth-of-type(2) {
      padding-bottom: 0.586667rem;
      color: #888;
    }
  }
  .bot {
    display: block;
    height: 0.2rem;
  }
}
.img {
  width: 9.2rem;
  margin: 0 auto;
  display: block;
  height: 8.933333rem;
}
.Collection {
  font-size: 0.373333rem;
  line-height: 0.4rem;
  color: #888888;
  text-align: center;
}
</style>
